<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>v-on 参数传参</title>
  <style>
    .box {
      width: 200px;
      height: 100px;
      margin: 0 auto;
      text-align: center;
      border: 2px, solid, black;
      border-radius: 10px;
    }
  </style>
</head>

<body>
  <div id='app'>
    <div class="box">
      <h3>自动贩卖机</h3>
      <button @click="buy(3)">可乐3元</button>
      <button @click="buy(9)">咖啡9元</button>
      <h3>银行卡余额：{{balance}}元</h3>
    </div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.js"></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        balance: 10

      },
      methods: {
        buy(money) {
          console.log(money);

          if (this.balance < money) {
            alert('余额不足')
            return
          }
          this.balance -= money
        }
      }

    })
  </script>
</body>

</html>